
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Imagination;
using Imagination.Display;
using Imagination.Partitioning;

#endregion

namespace ImagineBalls
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class ImagineBallsGame : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;

        ImaginationEngine engine;
        BallsScreen ballsScreen;
        PauseScreen pauseScreen;

        public ImagineBallsGame()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);
            engine = new ImaginationEngine(this);

            BoxPartitioner partitioner = new BoxPartitioner();
            this.Services.AddService(typeof(Partitioner), partitioner);

            //partitioner.RootZone.SplitXAxis(new Vector3(-120f, 0f, -120f), new Vector3(120f, 120f, 120f));
            //partitioner.RootZone.Zones[0].SplitXAxis();
            //partitioner.RootZone.Zones[0].Zones[0].SplitXAxis();
            //partitioner.RootZone.Zones[0].Zones[1].SplitXAxis();
            //partitioner.RootZone.Zones[1].SplitXAxis();
            //partitioner.RootZone.Zones[1].Zones[0].SplitXAxis();
            //partitioner.RootZone.Zones[1].Zones[1].SplitXAxis();

            //partitioner.RootZone.SplitZAxis4Way(new Vector3(-120f, 0f, -120f), new Vector3(120f, 120f, 120f));
            
            partitioner.RootZone.SplitZAxis(new Vector3(-120f, 0f, -120f), new Vector3(120f, 120f, 120f));
            //partitioner.RootZone.Zones[0].SplitZAxis();
            //partitioner.RootZone.Zones[0].Zones[0].SplitZAxis();
            //partitioner.RootZone.Zones[0].Zones[1].SplitZAxis();
            //partitioner.RootZone.Zones[1].SplitZAxis();
            //partitioner.RootZone.Zones[1].Zones[0].SplitZAxis();
            //partitioner.RootZone.Zones[1].Zones[1].SplitZAxis();
        }

        public GraphicsDeviceManager Graphics
        {
            get { return graphics; }
        }

        public ContentManager Content
        {
            get { return content; }
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            ballsScreen = new BallsScreen(this);
            pauseScreen = new PauseScreen(this);
            engine.ScreenManager.ActiveScreens.Push(ballsScreen);
            engine.ScreenManager.ActiveScreens.Push(pauseScreen);
            engine.ToggleDebugScreen();
        }

        /// <summary>
        /// Unload your graphics content.  If unloadAllContent is true, you should
        /// unload content from both ResourceManagementMode pools.  Otherwise, just
        /// unload ResourceManagementMode.Manual content.  Manual content will get
        /// Disposed by the GraphicsDevice during a Reset.
        /// </summary>
        /// <param name="unloadAllContent">Which type of content to unload.</param>
        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent == true)
            {
                content.Unload();
            }
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the default game to exit on Xbox 360 and Windows
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            if (GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed)
                pauseScreen.IsActive = true;

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        //protected override void Draw(GameTime gameTime)
        //{
        //    base.Draw(gameTime);
        //}


    }
}